<template>
  <div class="public-container">
    <!-- 轮播图部分 -->
    <el-carousel :interval="4000" type="card" height="400px">
      <el-carousel-item v-for="(item, index) in carouselItems" :key="index">
        <div class="carousel-content" :style="{ backgroundImage: `url(api/${item.img})` }">
          <div class="carousel-text">
            <h2>{{ item.name }}</h2>
            <p>{{ item.price }}</p>
          </div>
        </div>
      </el-carousel-item>
    </el-carousel>
    <!-- 内容 -->
    <el-row :gutter="20"> <!-- 设置列间距 -->
      <el-col
          v-for="(item, index) in products"
          :key="item.id"
          :span="6"
          :md="24"
          :lg="12"
          :xl="6"
          class="mb-20"
          style="margin-bottom: 20px"
      >
        <el-card :body-style="{ padding: '0px',backgroundColor: '#494747',color: '#ffffff' }">
          <img :src="'/api'+item.img" class="image">
          <div style="padding: 14px;">
            <div style="font-size: 24px;">
              <span>{{ item.name }}</span>
            </div>
            <div style="color: #9e9e9e;margin-top: 10px">
              描述: <span>{{ item.note }}</span>
            </div>
            <div style="margin-top: 10px">
              价格: <span style="color: red">{{ item.price }}￥</span>
            </div>


            <div class="bottom clearfix">
              <time class="time">{{ item.createTime }}</time>
              <el-button type="text" class="button" @click="buy(item)">购买</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'PublicIndex',
  data() {
    return {
      carouselItems: [],
      products: []
    }
  },
  created() {
    this.init()
  },
  methods: {
    buy(item) {
      this.$message.success('购买成功')
    },
    init() {
      //查询轮播图
      this.request.post("/public/list").then(res => {
        this.carouselItems = res.data
      })
      //查询商品
      this.request.post("/public/orders").then(res => {
        this.products = res.data
      })
    }

  }
}
</script>

<style scoped>
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

.image {
  width: 100%;
  height: 400px;
}

.public-container {
  padding: 20px;
  color: white;
}

/* 轮播图样式 */
.carousel-container {
  margin-bottom: 40px;
}

.carousel-content {
  height: 100%;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.carousel-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
}

.carousel-text {
  position: relative;
  color: white;
  text-align: center;
  padding: 20px;
}

.carousel-text h2 {
  font-size: 2.5em;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.carousel-text p {
  font-size: 1.2em;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

/* 原有样式 */
.welcome-card {
  margin-bottom: 20px;
}

.welcome-content {
  text-align: center;
  padding: 20px 0;
}

.feature-list {
  margin-top: 30px;
}

.feature-list .el-card {
  cursor: pointer;
  text-align: center;
  padding: 20px;
  transition: all 0.3s;
}

.feature-list .el-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
}

.feature-list i {
  font-size: 48px;
  color: #409EFF;
  margin-bottom: 15px;
}

.feature-list h3 {
  margin: 10px 0;
  color: #303133;
}

.feature-list p {
  color: #606266;
  font-size: 14px;
}
</style>
